<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/conn.asp"-->
<!--#include file="lib/saferequest.asp"-->
<!--#include file="lib/error_write.asp"-->
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<link rel="stylesheet" href="lib/sheet.css" type="text/css" />
<link type="text/css" rel="stylesheet" href="lib/jquery_ui_lastest/themes/base/jquery_ui_lastest.css" />
<!-- jquery和ui -->
<script type="text/javascript" src="lib/jquery_lastest.js"></script>
<script type="text/javascript" src="lib/jquery_ui_lastest/jquery_ui_lastest.js"></script>
<script type="text/javascript" src="lib/jquery_ui_lastest/i18n/jquery_ui_datepicker_zh_CN_lastest.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&language=zh-CN"></script>
<script type="text/javascript">
	$(function() {
		$.datepicker.setDefaults({
			changeMonth: true,
			changeYear: true
		});
		$(".datepicker").datepicker();
		$(".contable").addClass("ct");	//载入table样式
		$(".contable th").addClass("ch").css("background-color","silver");	//载入th样式
		$(".contable td").addClass("ld");	//载入td样式
		function didian_xiangxing(){
			$.get("yj.asp",{didian:$("#didian").val(),xiangxing:$("#xx").val()},function(data){
				//alert(data);
				if (!data){
					$("#yj,#jsj,#chanzhi").val(0);
					return false;
				}
				$("#yj").val(data.yunjia);
				$("#zdyj").html(data.yunjia);

				//$("#rlf,#sjrlf").val(data.zdrlf);
				if(data.jsj==""){$("#jsj").val("0")} else {$("#jsj").val(data.jsj)};
				//$("#dz").val((parseFloat($("#jgf").val())+parseFloat($("#jsj").val()))*0.6);
				$("#zddz").html((parseFloat($("#yfjgf").val())+parseFloat($("#jsj").val()))*0.6);
				$("#chanzhi").val(data.chanzhi);
			},"json");
		
		}
		$("#dd,#xx,#didian").change(function(){
			didian_xiangxing();
		});
		$("#tixiang,#huanxiang").change(function(){
			var tx=txf=hx=hxf=0;
			$.get("tx.asp",{tx:$("#tixiang").val()},function(data){
				//alert(data);
				if(!data){ tx=0;txf=0;}else{ tx=data.tx;txf=data.txf;}
				$("#jgf").val(tx+hx);
				$("#yfjgf").val(txf+hxf);
				//$("#dz").val((tx+hx+parseFloat($("#jsj").val()))*0.6);
				$("#zddz").html((txf+hxf+parseFloat($("#jsj").val()))*0.6);
			},"json");
			$.get("hx.asp",{hx:$("#huanxiang").val()},function(data){
				//alert(data);
				if(!data){ hx=0;hxf=0;}else{ hx=data.hx;hxf=data.hxf;}
				$("#jgf").val(tx+hx);
				$("#yfjgf").val(txf+hxf);
				//$("#dz").val((tx+hx+parseFloat($("#jsj").val()))*0.6);
				$("#zddz").html((txf+hxf+parseFloat($("#jsj").val()))*0.6);
			},"json");
		});
		$("#tyr").keyup(function(){
			var tyr=$("#tyr");
			$("#ttyr").css("left",(tyr.offset().left).toString()+"px").css("top",(tyr.offset().top+tyr.height()+5).toString()+"px").css("width",(tyr.width()+6).toString()+"px");
			//alert(tyr.offset().left);
			//e.preventDefault();
			if(tyr.val().length>0){
				$.get("tyr.asp",{tyr:$(this).val()},function(data){
					if(!data.length){
						$("#ttyr").css("visibility","hidden");
					}else{
						//alert(data[0].tyr);

						var ttyr="";
						for(var i=0;i<data.length;i++)
						{
							ttyr+="<tr><td class='gac_c'>"+data[i].tyr+"</td></tr>";
							//alert(ttyr);
						}
						//alert(ttyr);
						$("#ttyr").html(ttyr).css("visibility","visible");
						$("#ttyr tr").mouseover(function(){	//对返回的dom进行mouseowver事件捕获
							$(this).toggleClass("gac_b");	//添加css样式
						}).mouseout(function(){	//对dom进行mouseout事件捕获
							$(this).toggleClass("gac_b");	//移除css样式
						});
						$("#ttyr td").click(function(){
							tyr.val($(this).text());
							$("#ttyr").css("visibility","hidden");
						});
						tyr.blur(function(){
							setTimeout("$('#ttyr').css('visibility','hidden');", 200);
						});
					}
				},"json");
			}
		});
		
		$(".opensidebar").click(function(){
			$("#content").css("margin","0 0 0 210px");
			$("#sidebar").show();
		});
		$(".closesidebar").click(function(){
			$("#content").css("margin","0");
			$("#sidebar").hide();
		});
		
		function customer_option(q){
			var query_sql_string="customer_id,customer_name,customer_address,customer_phone,customer_owner,salesman_name,equip_address,customer_memo,salesman_phone";
			$.getJSON("readCustomer.asp?l="+q+"&query="+query_sql_string,function(customerdata){
					//if(customerdata.length<20){
					//	$("#sidecontent").attr("size",customerdata.length).css("width","200px");
					//}
					//else{
					//	$("#sidecontent").attr("size","20").css("width","200px");
					//}
					$("#sidecontent").html("");
					$.each(customerdata,function(i,item){
						//$("#sidecontent").append("<option id='customer_"+item.customer_id+"' rel='"+						item.customer_name+"|"+						item.customer_owner+"|"+						item.customer_address+"|"+						item.customer_phone+"|"+						item.equip_address+"|"+						item.salesman_name+"|"+						item.customer_memo+"|"+						item.salesman_phone+						"' value='"+item.customer_id+"'>"+item.customer_name+"</option>");
						$("#sidecontent").append("<option id='customer_"+item.customer_id+"' value='"+item.customer_id+"'>"+item.customer_name+"</option>");
					});
					//$("#sidecontent").html(cdata);
					$("#sidecontent>option").dblclick(function(e){
						//alert($(this).attr("rel"));
						//var customer_array=$(this).attr("rel").split("|");
						//$("#client").val(customer_array[0]);
						//$("#contacts").val(customer_array[1]+" "+customer_array[2]+" "+customer_array[3]);
						//$("#hz").val(customer_array[5]);
						//$("#attentions").val(customer_array[6]);
						//$("#customer_id").val($(this).val());
				
						//alert(customerdata[$(this).index()].customer_name);
						var j=$(this).index();
						//alert(j);
						$("#client").val(customerdata[j].customer_name);
						$("#contacts").val(customerdata[j].customer_owner+" "+customerdata[j].customer_address+" "+customerdata[j].customer_phone);
						$("#hz").val(customerdata[j].salesman_name);
						$("#attentions").val(customerdata[j].customer_memo);
						$("#customer_id").val($(this).val());
						

						$("#dd>option").each(function(){
								//alert($(this).val());
							//if($(this).val()==customer_array[4]){
							if($(this).val()==customerdata[j].equip_address){
								$(this).attr("selected","selected");
								$("#didian").val(customerdata[j].equip_address);
								didian_xiangxing();
								return false;				//中断循环
							}
						});
					});
			});
		
		
		}
		
		$("#selCustomer").click(function(){
			customer_option($("#quick").val());
		});
		$("#quick").keyup(function(){
			customer_option($(this).val());
		});
		$("#client,#contacts,#hz").click(function(){
			alert("请使用客户选择功能，直接录入功能已经关闭！");
		});
		
		$("#tyr").change(function(){
			
			$("#yb_freight").val($("#tyr option:selected").attr("name"));
		});
		
		
		
	});

</script>
<!--#include file="lib/keydown.asp"-->

</head>
<body>
<%
call CheckRights(1,4)

id=saferequest("id",1)
set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from yb LEFT JOIN cl ON yb.cyr = cl.clid where post=1 and id="&id
rs.open sql,conn,1,1
if rs.eof then 
	response.write("找不到货单或在非本岗位中！")
	response.end
end if
if rs("yb_verify") then response.Redirect("view_cw.asp?id="&id)


if request.form("tj")="下单" or request.form("tj")="保存" Then
	if request.form("tj")="下单" Then post=2 else post=rs("post")
	client=trim(SafeRequest("client",0))
	contacts=trim(SafeRequest("contacts",0))
	hz=trim(SafeRequest("hz",0))
	attentions=trim(SafeRequest("attentions",0))
	xdr=trim(SafeRequest("xdr",0))
	if xdr="" then error_write "3","没有填写[下单人]"
	sj=trim(replace(request.form("sj"),"'","''"))
	rq=trim(replace(request.form("rq"),"'","''"))
	if rq="" then error_write "1","没有填写[日期]"
	xdrq=trim(SafeRequest("xdrq",0))
	if xdrq="" then error_write "4","没有填写[下单日期]"
	tyr=trim(replace(request.form("tyr"),"'","''"))
	if tyr="" then error_write "2","没有填写[托运人]"
	yb_freight=SafeRequest("yb_freight",1)
	dd=trim(replace(request.form("dd"),"'","''"))
	dd=trim(replace(request.form("didian"),"'","''"))
	cmhc=trim(replace(request.form("cmhc"),"'","''"))
	tdh=trim(replace(request.form("tdh"),"'","''"))
	xx=trim(replace(request.form("xx"),"'","''"))
	tx=trim(SafeRequest("tixiang",0))
	hx=trim(SafeRequest("huanxiang",0))
	yj=trim(SafeRequest("yj",0))
	if yj="" then yj=0
	jsj=trim(SafeRequest("jsj",0))
	if jsj="" then jsj=0
	chanzhi=trim(SafeRequest("chanzhi",0))
	if chanzhi="" then chanzhi=0
	jgf=trim(SafeRequest("jgf",0))
	if jgf="" then jgf=0
	yfjgf=trim(SafeRequest("yfjgf",0))
	if yfjgf="" then yfjgf=0
	dz=trim(SafeRequest("dz",0))
	if dz="" then dz=0
	customer_id=SafeRequest("customer_id",1)
	sql="update yb set sj='"&sj&"',rq='"&rq&"',tyr='"&tyr&"',yb_freight="&yb_freight&",dd='"&dd&"',cmhc='"&cmhc&"',tdh='"&tdh&"',xx='"&xx&"',client='"&client&"',contacts='"&contacts&"',hz='"&hz&"',attentions='"&attentions&"',gxry='"&session("MM_Name")&"',gxsj='"&Now()&"',post="&post&",xdr='"&xdr&"',xdrq='"&xdrq&"',tx='"&tx&"',hx='"&hx&"',yj="&yj&",jsj="&jsj&",jgf="&jgf&",yfjgf="&yfjgf&",dz="&dz&",yb_customer="&customer_id&",chanzhi="&chanzhi&" where id="&id
	'response.write sql
	set cmd=Server.CreateObject("ADODB.Command")
	cmd.ActiveConnection=conn
	cmd.CommandText = sql
	cmd.Execute
	response.write("编辑成功，可以继续编辑本记录")
	view_url="view_cw.asp?id="&id
	response.Redirect(view_url)
end if


%>
<div id="sidebar">
	<button class="closesidebar" type="button" style="width:200px">关闭</button>
	<input id="quick" style="width:198px" />
	<div>
		<select id="sidecontent" size="20" style="width:200px"></select>
	</div>
</div>
<div id="content">

<form name="form1" method="post" action="#">
<table class="contable">
	<thead>
		<tr>
			<th colspan="4" class="lh"><font size="4">基本信息</font>(录入时间:<%=rs("lrsj")%>&nbsp;下单人:<input name="xdr" id="xdr" size="10" readonly="readonly" value="<%=rs("xdr")%>" />)</th>
    </tr>
	</thead>
  <tr>
    <th>序号</th>
    <td><%=id%></td>
    <th>货单日期</th>
    <td><input class="datepicker" name="rq" id="rq" value="<%=rs("rq")%>" /></td>
  </tr>
  <tr>
    <th>客户名称</th>
    <td colspan="4">
			<input name="client" id="client" size="80" readonly="readonly" value="<%=rs("client")%>" />
			<input name="customer_id" id="customer_id" type="hidden" value="<%=rs("yb_customer")%>" />
			<button id="selCustomer" class="opensidebar" type="button">选择客户</button>
		</td>
	</tr>
	<tr>
    <th>联系方式</th>
    <td colspan="4"><input name="contacts" id="contacts" size="80" readonly="readonly" value="<%=rs("contacts")%>" /></td>
  </tr>
	<tr>
    <th>业务员</th>
    <td colspan="4"><input name="hz" id="contacts" size="80" readonly="readonly" value="<%=rs("hz")%>" /></td>
  </tr>
  <tr>
    <th>托运人</th>
    <td><select id="tyr" name="tyr">
		<%
		set rs_tyr = Server.CreateObject("ADODB.Recordset")
sql="select freight_id,freight_name from freight order by freight_name"
rs_tyr.open sql,conn,1,1
While Not rs_tyr.eof
%>
	 <option name="<%=rs_tyr("freight_id")%>" value="<%=rs_tyr("freight_name")%>" <%if rs_tyr("freight_id")=rs("yb_freight") then response.write("selected='selected'")%>><%=rs_tyr("freight_name")%></option>
<%
rs_tyr.movenext
Wend
rs_tyr.close
%>					
		</select>
		<input type="hidden" id="yb_freight" name="yb_freight" value="<%=rs("yb_freight")%>" />
		</td>
    <th>承运人</th>
    <td><%=rs("cph")%>(<%=rs("tel")%>)</td>
  </tr>
  <tr>
    <th>地点</th>
    <td><input name="didian" id="didian" type="hidden" value="<%=rs("dd")%>" />
		<select name="dd" id="dd" disabled="disabled">
        <option value=""></option>
		<%
		set rs_dd = Server.CreateObject("ADODB.Recordset")
		sql="select didian from yj group by didian"
		rs_dd.open sql,conn,1,1
		while not rs_dd.eof
		%>
        <option value="<%=rs_dd("didian")%>" <%If rs("dd")=rs_dd("didian") Then response.write("selected='selected'")%>><%=rs_dd("didian")%></option>
	<%
			rs_dd.movenext()
		wend
		rs_dd.close
	%>
      </select>
			</td>
			<th>时间</th>
			<td><select id="sj" name="sj">
				<option value="0:00" <%if rs("sj")="0:00:00" then response.write("selected")%>>0:00</option>
				<option value="1:00" <%if rs("sj")="1:00:00" then response.write("selected")%>>1:00</option>
				<option value="2:00" <%if rs("sj")="2:00:00" then response.write("selected")%>>2:00</option>
				<option value="3:00" <%if rs("sj")="3:00:00" then response.write("selected")%>>3:00</option>
				<option value="4:00" <%if rs("sj")="4:00:00" then response.write("selected")%>>4:00</option>
				<option value="5:00" <%if rs("sj")="5:00:00" then response.write("selected")%>>5:00</option>
				<option value="6:00" <%if rs("sj")="6:00:00" then response.write("selected")%>>6:00</option>
				<option value="7:00" <%if rs("sj")="7:00:00" then response.write("selected")%>>7:00</option>
				<option value="8:00" <%if rs("sj")="8:00:00" then response.write("selected")%>>8:00</option>
				<option value="9:00" <%if rs("sj")="9:00:00" then response.write("selected")%>>9:00</option>
				<option value="10:00" <%if rs("sj")="10:00:00" then response.write("selected")%>>10:00</option>
				<option value="11:00" <%if rs("sj")="11:00:00" then response.write("selected")%>>11:00</option>
				<option value="12:00" <%if rs("sj")="12:00:00" then response.write("selected")%>>12:00</option>
				<option value="13:00" <%if rs("sj")="13:00:00" then response.write("selected")%>>13:00</option>
				<option value="14:00" <%if rs("sj")="14:00:00" then response.write("selected")%>>14:00</option>
				<option value="15:00" <%if rs("sj")="15:00:00" then response.write("selected")%>>15:00</option>
				<option value="16:00" <%if rs("sj")="16:00:00" then response.write("selected")%>>16:00</option>
				<option value="17:00" <%if rs("sj")="17:00:00" then response.write("selected")%>>17:00</option>
				<option value="18:00" <%if rs("sj")="18:00:00" then response.write("selected")%>>18:00</option>
				<option value="19:00" <%if rs("sj")="19:00:00" then response.write("selected")%>>19:00</option>
				<option value="20:00" <%if rs("sj")="20:00:00" then response.write("selected")%>>20:00</option>
				<option value="21:00" <%if rs("sj")="21:00:00" then response.write("selected")%>>21:00</option>
				<option value="22:00" <%if rs("sj")="22:00:00" then response.write("selected")%>>22:00</option>
				<option value="23:00" <%if rs("sj")="23:00:00" then response.write("selected")%>>23:00</option>
			</select>
		</td>
	</tr>
	<tr>
    <th>船名/航次</th>
    <td><input name="cmhc" id="cmhc" value="<%=rs("cmhc")%>" /></td>
		<th>下单日期</th>
		<td><input class="datepicker" name="xdrq" id="xdrq" value="<%=rs("xdrq")%>"></td>
  </tr>
  <tr>
    <th>提单号</th>
    <td><input name="tdh" id="tdh" value="<%=rs("tdh")%>" /></td>
    <th>箱型</th>
    <td>
      <select name="xx" id="xx">
        <option value="40" <%if rs("xx")="40" then response.write("selected")%>>40</option>
        <option value="20" <%if rs("xx")="20" then response.write("selected")%>>20</option>
        <option value="45" <%if rs("xx")="45" then response.write("selected")%>>45</option>
      </select>
	  </td>
  </tr>
  <tr>
    <th>箱号</th>
    <td><%=rs("xh")%></td>
    <th>封号</th>
    <td><%=rs("fh")%></td>
  </tr>
	<thead>
		<tr>
			<th colspan="4" class="lh"><font size="4">基本费用</font></th>
    </tr>
	</thead>
  <tr>
    <th>提箱</th>
    <td>
		<select name="tixiang" id="tixiang">
        <option value=""></option>
		<%
		set rs_tx = Server.CreateObject("ADODB.Recordset")
		sql="select * from tx"
		rs_tx.open sql,conn,1,1
		while not rs_tx.eof
		%>
        <option value="<%=rs_tx("tixiang")%>" <%If rs("tx")=rs_tx("tixiang") Then response.write("selected='selected'")%>><%response.write(rs_tx("tixiang")&"("&rs_tx("tixiangjiage")&")")%></option>
	<%
			rs_tx.movenext()
		wend
		rs_tx.close
	%>
      </select>
	</td>
    <th>还箱</th>
    <td>
	<select name="huanxiang" id="huanxiang">
        <option value=""></option>
		<%
		set rs_hx = Server.CreateObject("ADODB.Recordset")
		sql="select * from hx"
		rs_hx.open sql,conn,1,1
		while not rs_hx.eof
		%>
        <option value="<%=rs_hx("huanxiang")%>" <%If rs("hx")=rs_hx("huanxiang") Then response.write("selected='selected'")%>><%response.write(rs_hx("huanxiang")&"("&rs_hx("huanxiangjiage")&")")%></option>
	<%
			rs_hx.movenext()
		wend
		rs_hx.close
	%>
      </select>
</td>
  </tr>
  <tr>
    <th>应收进港费</th>
    <td><input name="jgf" id="jgf" value="<%=rs("jgf")%>" readonly="readonly" title="应收进港费=提箱+还箱" /> 应收进港费=提箱+还箱</td>
    <th>应付进港费</th>
    <td><input name="yfjgf" id="yfjgf" value="<%=rs("yfjgf")%>" readonly="readonly" /> 堆存费<%=rs("dcf")%></td>
  </tr>
  <tr>
    <th>应收运费</th>
    <td><input name="yj" id="yj" value="<%=rs("yj")%>" readonly="readonly" title="运价=地点+箱型" /> 运价:<span id="zdyj"><%=rs("yj")%></span></td>
    <th>应付运费</th>
    <td><input name="jsj" id="jsj" value="<%=rs("jsj")%>" readonly="readonly" /></td>
  </tr>
  <tr>
    <th>垫资</th>
    <td><input name="dz" id="dz" value="<%=rs("dz")%>" title="垫资=（应付运费+进港费）×60%" /> 垫资:<span id="zddz"><%=rs("dz")%></span></td>
    <th>产值</th>
    <td><input name="chanzhi" id="chanzhi" value="<%=rs("chanzhi")%>" readonly="readonly" /></td>
  </tr>
  <tr>
    <th>注意事项</th>
    <td colspan="3"><textarea rows="3" cols="80" id="attentions" name="attentions"><%=rs("attentions")%></textarea></td>
  </tr>
  <tr>
    <th>车队备注</th>
    <td colspan="3"><%=rs("bz")%></td>
  </tr>
</table>
<br />
<input class="bt" type="submit" name="tj" value="保存" onClick="return confirm('确定编辑货单吗？')" />&nbsp;&nbsp;&nbsp;&nbsp;
<input class="bt" type="submit" name="tj" value="下单" />&nbsp;&nbsp;&nbsp;&nbsp;
<input class="bt" type="reset" />
</form>
<br />
<p>最后更改人:<%=rs("gxry")%>&nbsp;最后更新时间:<%=rs("gxsj")%></p>
<br />
<p>
操作>> | <a href="add_cw.asp">货单录入</a> | <a href="view_cw.asp?id=<%=id%>">货单查看</a> | <a href="delete_cw.asp?id=<%=id%>" onClick="return confirm('你真的想删除这个货单吗？')">货单删除</a> |
</p>
</div>
<div id="map_canvas" style="width: 100%; height: 500px"></div>
<%
rs.close
Set rs=Nothing
conn.close
Set conn=nothing
%>
</body>
</html>
